#pragma once
#include"./hardware_resource/VPU/VPU.h"
#include"./hardware_resource/SPU/SPU.h"
#include"memory_module/memory_space.h"
#include"execution_module/execution_engine.h"

class DSP_node{
public:
    DSP_node(Instruction_Mem* instr_mem, memory* GSM) {
        //初始化node内的各个硬件模块
        //TODO:V_memory和memory的size和start_offset均为测试时的临时值，后续需要根据实际情况进行调整
        AM = new V_memory(100000, 123);
        SM = new memory(100000, 456);
        RF = new RegisterFile();
        //TODO:start_addr暂时设为1，后续考虑如何设置
        //用于hthread_group_create(int cluster_id, int num)创建的线程组
        //即不带参数的线程组，没有指定要执行的函数名，默认从地址1开始执行
        engine = new Engine(1, AM, SM, GSM, RF, instr_mem);
        vpu = new VPU(AM, RF, this->engine->getWCM());
        spu = new SPU(SM, RF, this->engine->getWCM());
        this->engine->set_vpu(this->vpu);
        this->engine->set_spu(this->spu);
    }
    DSP_node(Instruction_Mem* instr_mem, memory* GSM, addr_size_t start_addr) {
        //初始化node内的各个硬件模块
        //V_memory和memory的size和start_offset均为测试时的临时值，后续需要根据实际情况进行调整
        AM = new V_memory(100000, 123);
        SM = new memory(100000, 456);
        RF = new RegisterFile();
        //用于hthread_group_create(int cluster_id, int num, char *func_name, int scalarArgs, int ptrArgs, uint64_t *argArray)创建的线程组
        //即带参数的线程组，从指定的start_addr开始执行
        engine = new Engine(start_addr, AM, SM, GSM, RF, instr_mem);
        vpu = new VPU(AM, RF, this->engine->getWCM());
        spu = new SPU(SM, RF, this->engine->getWCM());
        this->engine->set_vpu(this->vpu);
        this->engine->set_spu(this->spu);
    }
    ~DSP_node() {
        delete AM;
        delete SM;
        delete RF;
        delete vpu;
        delete spu;
        delete engine;
    }

    Engine* get_engine();

private:
    VPU* vpu;
    SPU* spu;
    //使用DMA时，所有片上内存均按字对齐
    //AM访问只能按字对齐
    V_memory* AM;
    //SM和GSM的访问可以按半字对齐
    memory* SM;
    RegisterFile* RF;
    Engine* engine;
};